package kr.pe.johnkim.waiting.mobile.controller;

import kr.pe.johnkim.waiting.mobile.domain.WaitingMemberRecommendation;
import kr.pe.johnkim.waiting.mobile.service.WaitingMemberRecommendationService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Waiting 추천 이력 controller class 이다.
 * 추천을 등록하는 사용자에 관한 메소드들이다.
 *
 * @author : John_Kim <cale9797@gmail.com>
 * @date : 13. 7. 15.
 */
@Controller
@RequestMapping(value = "/waitingMemberRecommendationController")
public class WaitingMemberRecommendationController {

    // SLF4J Logging
    private Logger logger = LoggerFactory.getLogger(WaitingMemberRecommendationController.class);

    @Autowired
    private WaitingMemberRecommendationService waitingMemberRecommendationService;

    /**
     * 사용자의 추천 중복을 확인 한다.
     *
     * @param waitingMemberRecommendation
     * @return
     * @throws Exception
     */
    @RequestMapping(value="/selectDuplicationMemberRecommendation", method = RequestMethod.POST)
    @ResponseStatus(HttpStatus.OK)
    @ResponseBody
    public WaitingMemberRecommendation selectDuplicationMemberRecommendation(@RequestBody WaitingMemberRecommendation waitingMemberRecommendation) throws Exception {
        logger.info("selectDuplicationMemberRecommendation");

        return this.waitingMemberRecommendationService.selectDuplicationMemberRecommendation(waitingMemberRecommendation);
    }

    /**
     * 사용자 추천을 등록 한다.
     *
     * @param waitingMemberRecommendation
     * @return
     * @throws Exception
     */
    @RequestMapping(value="/registerMemberRecommendation", method = RequestMethod.POST)
    @ResponseStatus(HttpStatus.OK)
    @ResponseBody
    public WaitingMemberRecommendation registerMemberRecommendation(@RequestBody WaitingMemberRecommendation waitingMemberRecommendation) throws Exception {
        logger.info("registerMemberRecommendation");

        WaitingMemberRecommendation result = new WaitingMemberRecommendation();
        try {
            this.waitingMemberRecommendationService.registerMemberRecommendation(waitingMemberRecommendation);
            result.setResult("SUCCESS");
            logger.info("success to register member recommendation.");
        } catch (Exception e) {
            result.setResult("FAIL");
            logger.error("fail to register member recommendation.");
        }

        return result;
    }

    /**
     * 사용자 추천을 비활성화 한다.
     *
     * @param waitingMemberRecommendation
     * @return
     * @throws Exception
     */
    @RequestMapping(value="/updateDeactivateMemberRecommendation", method = RequestMethod.POST)
    @ResponseStatus(HttpStatus.OK)
    @ResponseBody
    public WaitingMemberRecommendation updateDeactivateMemberRecommendation(@RequestBody WaitingMemberRecommendation waitingMemberRecommendation) throws Exception {
        logger.info("updateDeactivateMemberRecommendation");

        WaitingMemberRecommendation result = new WaitingMemberRecommendation();

        try {
            this.waitingMemberRecommendationService.updateDeactivateMemberRecommendation(waitingMemberRecommendation);
            result.setResult("SUCCESS");
            logger.info("success to update deactivate member recommendation.");
        } catch (Exception e) {
            result.setResult("FAIL");
            logger.error("fail to update deactivate member recommendation.");
        }

        return result;
    }

    /**
     * 특정 사용자의 추천 목록을 가져 온다.
     *
     * @param waitingMemberRecommendation
     * @return
     * @throws Exception
     */
    @RequestMapping(value="/selectMemberRecommendationList", method = RequestMethod.POST)
    @ResponseStatus(HttpStatus.OK)
    @ResponseBody
    public List<WaitingMemberRecommendation> selectMemberRecommendationList(@RequestBody WaitingMemberRecommendation waitingMemberRecommendation) throws Exception {
        logger.info("selectMemberRecommendationList");

        return this.waitingMemberRecommendationService.selectMemberRecommendationList(waitingMemberRecommendation);
    }

    /**
     * 특정 가맹점에 대한 추천 목록을 가져 온다.
     *
     * @param waitingMemberRecommendation
     * @return
     * @throws Exception
     */
    @RequestMapping(value="/selectMerchantRecommendationList", method = RequestMethod.POST)
    @ResponseStatus(HttpStatus.OK)
    @ResponseBody
    public List<WaitingMemberRecommendation> selectMerchantRecommendationList(@RequestBody WaitingMemberRecommendation waitingMemberRecommendation) throws Exception {
        logger.info("selectMerchantRecommendationList");

        return this.waitingMemberRecommendationService.selectMerchantRecommendationList(waitingMemberRecommendation);
    }
}
